﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace GylCSharpUtils.Common.Utils {
    public class ArrayUtils {



        /// <summary>
        /// 将数组转为字符串
        /// </summary>
        /// <typeparam name="T">类型</typeparam>
        /// <param name="arr">数组</param>
        /// <param name="formatFunc">对象格式化</param>
        /// <returns></returns>
        public static string ToStr<T>(T[] arr, string separator=",") {
            if(arr == null) return "null";
            if(arr.Length == 0) return "[]";
            Type type = typeof(T);
            string c=null;
            if(typeof(string) == type) {
                c = "\"";
            } else if(typeof(char) == type) {
                c = "'";
            }
            if(c != null) {
                return string.Format("[{0}]", string.Join(separator,
                    arr.Select(o => o == null ? "null" : string.Format($"{c}{o}{c}"))
                ));
            }
            return string.Format("[{0}]", string.Join(separator, arr));
            
            
        }
    }
}
